

public class OldBackupDEFStringConverter {
	
	private static String stringDEF;
	private static String startXML = "<xsl:value-of select=\"";
	private static String endXML = "\"/>";
	private static String stringStartIf = "<xsl:choose><xsl:when test=\"";
	private static String stringEndIf = "</xsl:when></xsl:choose>";
	private static String fmtStart = "<xsl:value-of select='";
	//private static String fmtEnd = ")' />";
	private static String loopStart = "<xsl:for-each select=\"ApVariables/";
	private static String loopEnd = "</xsl:for-each>";
	
	private static String[] bracketStrings = new String[250];
	private static String[][] curlyBracketStrings = new String[250][250]; //first is changed, second is array of all {} strings in the first
	private static String[] parenBracketStrings = new String[250];
	
	private static String[] atStrings = new String[250];
	
	private static String[] spaceTextStrings = new String[250];
	
	private static String[] allStringsDEF = new String[250];
	
	private static String[] compareStrings = new String[250];
	
	private static String[] padStrings = new String[250];
	private static String[] padNumOfSpaces = new String[250];
	private static String[] padAuxiliary = new String[250];
	private static String[] padID = new String[250];
	
	private static String[] loopStrings = new String[250];
	private static String[] loopCondition = new String[250];
	private static String[] loopOutputs = new String[250];
	private static String[] loopID = new String[250];
	
	private static String[] mathStrings = new String[250];
	private static String[] realMathStrings = new String[250];
	private static String[][] mathPieces = new String[250][250];
	
	private static String[] fmtStrings = new String[250];
	private static String[] fmtAuxiliary = new String[250];
	private static String[] fmtFormat = new String[250];
	private static String[] fmtType = new String[250];
	
	private static String[] modifiedAts = new String[250];
	
	private static String[] modifiedBrackets = new String[250];
	private static String[] modifiedParenBrackets = new String[250];
	private static String[] modifiedCurlyBrackets = new String[250];
	private static String[][] partlyModifiedCurlyBrackets = new String[250][250];
	
	private static String[] modifiedSpaceAndText = new String[250];
	
	private static String[] modifiedMATHs = new String[250];
	private static String[][] modifiedMathPieces = new String[250][250];
	private static String[] modifiedMathPiecesB = new String[250];
	private static String[][] mathVars = new String[250][250];
	private static String[] mathVarsB = new String[250];
	private static String[] modifiedMathStrings = new String[250];
	
	//private static String[] modifiedFMTs = new String[50];
	private static String[] modifiedFMTAuxs = new String[250];
	private static String[] modifiedFMTFormats = new String[250];
	
	private static String[] modifiedPads = new String[250];
	
	private static String[] modifiedLOOPs = new String[250];
	
	private static String[] allModifiedXML = new String[100];
	
	private static int[][] bracketIndexes = new int[250][2]; //first is changed, second 0=first, 1=last
	private static int[] usedIndexes = new int[500];
	private static int[][] orIndexes = new int[250][2];
	private static int[][] andIndexes = new int[250][2];
	
	private static int varIndex = 0;
	private static int loopVarCount = 0;
	private static int loopCount = 0;
	
	private static String stringXML = "";
	//private static String spaceString = startXML + "' '" + endXML;
	
private static int usedIndexCount = 0;
	
	public static String convert(String DEFString)
// input:
//			DEFString = @PADR(12,"@FMT("@MATH("((15 + 15) + (40/2))/5")","$###.00")",33)
//
// output:
//			<xsl:variable name="padr0">
//				<xsl:variable name="fmt1">
//					<xsl:variable name="math2">
//						<xsl:value-of select="15" />
//					</xsl:variable>
//				<xsl:variable name="math3">
//					<xsl:value-of select="15" />
//				</xsl:variable>
//				<xsl:variable name="math4">
//					<xsl:value-of select="40" />
//				</xsl:variable>
//				<xsl:variable name="math5">
//					<xsl:value-of select="2" />
//				</xsl:variable>
//				<xsl:variable name="math6">
//					<xsl:value-of select="5" />
//				</xsl:variable>
//					<xsl:value-of select="(($math2 + $math3) + ($math4 div $math5)) div $math6" />
//				</xsl:variable>
//	
//				<xsl:value-of select="format-number($fmt1,'$###.00')" />
//
//			</xsl:variable>
//			<xsl:value-of select="mismo:cOnePADR(12,$padr0,33)" />
	{
		stringDEF = DEFString;
		setUsedIndexes();
		splitToLogicalParts();
		simplifyAll();
		convertAll();
		
		setStringXML();
		return stringXML;
	}
	
	private static void setUsedIndexes()
	{
		for (int i=0; i<usedIndexes.length;i++)
		{
			usedIndexes[i] = -1;
		}
	}
	
	private static void setStringXML()
	{		
		int theInd = 0;
		int aInd = 0;
		int bInd = 0;
		int stInd = 0;
		int pInd = 0;
		int mInd = 0;
		int lInd = 0;
		
		for (String string : allStringsDEF)
		{
			if (string != null && string != "")
			{
			if (atStrings[aInd] == string)
			{
				allModifiedXML[theInd] = modifiedAts[aInd];
				aInd++;
			}
			else if (bracketStrings[bInd] == string)
			{
				allModifiedXML[theInd] = modifiedBrackets[bInd];
				bInd++;
			}
			else if (spaceTextStrings[stInd] == string)
			{
				allModifiedXML[theInd] = modifiedSpaceAndText[stInd];
				stInd++;
			}
			else if (padStrings[pInd] == string)
			{
				allModifiedXML[theInd] = modifiedPads[pInd];
				pInd++;
			}
			else if (loopStrings[lInd] == string)
			{
				allModifiedXML[theInd] = modifiedLOOPs[lInd];
				lInd++;
			}
			else if (mathStrings[mInd] == string)
			{
				allModifiedXML[theInd] = modifiedMATHs[mInd];
				mInd++;
			}
			theInd++;
			}
		}
		
		for (String xmlString : allModifiedXML)
		{
			if (xmlString != null)
			{
				stringXML = stringXML.concat(xmlString);
			}
		}
		
	}
	
	private static void simplifyAll()
	{
		simplifyBrackets();
		simplifyFMTs();
		simplifyPADs();
		simplifyLOOPs();
		simplifyMATHs();
		simplifyMATHsB();
	}
	
	private static void simplifyBrackets()
	{
		int parenIndex = 0;
		int curlyIndex = 0; //for 1st column
		
		for (String bracketString : bracketStrings)
		{
			int curlyIndex2 = 0; //for 2nd column
			if (bracketString != null && bracketString != "")
			{
			for (int i=0; i<bracketString.length();i++)
			{
			String newString = "";
			if (bracketString.charAt(i) == '(')
			{
				int j;
				for (j = i;j<bracketString.length() && bracketString.charAt(j) != ')';j++)
				{
					newString = newString.concat(String.valueOf(bracketString.charAt(j)));
				}
				newString = newString.concat(")");
				parenBracketStrings[parenIndex] = newString;
				
				parenIndex++;
				continue;
				
				
			}
			else if (bracketString.charAt(i) == '{')
			{
				int j;
				for (j = i;bracketString.charAt(j) != '}';j++)
				{
					newString = newString.concat(String.valueOf(bracketString.charAt(j)));
				}
				newString = newString.concat("}");
				curlyBracketStrings[curlyIndex][curlyIndex2] = newString;
				
				curlyIndex2++;
				continue;
				
			}
			}
			}
			curlyIndex++;
		}
		
	}
	
	private static void simplifyFMTs()
	{
		for (int i=0;i<50;i++)
		{
			fmtAuxiliary[i] = "";
			fmtFormat[i] = "";
		}
		int fmtIndex = 0;
		for (String fmtString : fmtStrings)
		{
			int[] quoteIndexes = new int [100];
			int quoteInd = 1;
			if (fmtString != null && fmtString != "")
			{				
				quoteIndexes[0] = 5;
				quoteIndexes[3] = fmtString.length() - 2;
				for (int i=6; i<fmtString.length() - 2;i++)
				{
					if (fmtString.charAt(i) == '"')
					{
						quoteIndexes[quoteInd] = i;
						quoteInd++;
					}
				}
				for (int j=quoteIndexes[0] + 1;j<quoteIndexes[1];j++)
				{
					fmtAuxiliary[fmtIndex] = fmtAuxiliary[fmtIndex].concat(String.valueOf(fmtString.charAt(j)));
				}
				for (int j=quoteIndexes[2] + 1;j<quoteIndexes[3];j++)
				{
					fmtFormat[fmtIndex] = fmtFormat[fmtIndex].concat(String.valueOf(fmtString.charAt(j)));
				}
				fmtIndex++;
			}
		}
		
	}
	
	private static void simplifyPADs()
	{
		for (int i=0; i<padStrings.length;i++)
		{
			if (padStrings[i] != null && padStrings[i] != "")
			{
				//init other pad strings
				padNumOfSpaces[i] = "";
				padAuxiliary[i] = "";
				padID[i] = "";
				int j;
				int k;
				for (j=6; j<padStrings[i].length() && Character.isDigit(padStrings[i].charAt(j));j++)
				{
					padNumOfSpaces[i] = padNumOfSpaces[i].concat(String.valueOf(padStrings[i].charAt(j)));
				}
				for (k=j+2; k<padStrings[i].length() && (padStrings[i].charAt(k) != '"' || k <= j+2);k++)
				{
					padAuxiliary[i] = padAuxiliary[i].concat(String.valueOf(padStrings[i].charAt(k)));
				}
				for (int m=k+2; m<padStrings[i].length() && padStrings[i].charAt(m) != ')';m++)
				{
					padID[i] = padID[i].concat(String.valueOf(padStrings[i].charAt(m)));
				}				
			}
		}
	}
	
	private static void simplifyLOOPs()
	{
		int parenIndex = 0;
		int curlyIndex = 0;
		int idIndex = 0;
		
		for (String loopString : loopStrings)
		{
			if (loopString != null && loopString != "")
			{
				loopID[idIndex] = "";
				for (int j=7; j<loopString.length() && loopString.charAt(j) != '(';j++)
				{
					loopID[idIndex] = loopID[idIndex].concat(String.valueOf(loopString.charAt(j)));
				}
				idIndex++;
				
			for (int i=0; i<loopString.length();i++)
			{
			String newString = "";
			if (loopString.charAt(i) == '(')
			{
				int j;
				for (j = i+1;j<loopString.length() && loopString.charAt(j) != ')';j++)
				{
					newString = newString.concat(String.valueOf(loopString.charAt(j)));
				}
				loopCondition[parenIndex] = newString;
				parenIndex++;
				continue;
				
			}
			else if (loopString.charAt(i) == '{')
			{
				int j;
				for (j = i+1;loopString.charAt(j) != '}';j++)
				{
					newString = newString.concat(String.valueOf(loopString.charAt(j)));
				}
				loopOutputs[curlyIndex] = newString;
				continue;
			}
			
			}
			}
			curlyIndex++;
		}
	}
	
	private static void simplifyMATHs()
	{
		int mathCount = 0;
		
		for (String math : mathStrings)
		{
			if (math != null && math != "")
			{
				realMathStrings[mathCount] = "";				
				for (int i=7; i<math.length() && math.charAt(i) != '"'; i++)
				{
					realMathStrings[mathCount] = realMathStrings[mathCount].concat(String.valueOf(math.charAt(i)));
				}				
				mathCount++;
			}
		}
/*
		for (int i=0; i<realMathStrings.length;i++)
		{
			if (realMathStrings[i] != null && realMathStrings[i] != "")
			{
				int[] usedIndexes = new int[100];
				int uIndex = 0;
				int parenIndex = 0;
			
				for (int j=0; j<realMathStrings[i].length(); j++)
				{
					String newString = "";
					if (realMathStrings[i].charAt(j) == '(' && (isNotUsed(j, usedIndexes) || j==0))
					{
						int pCount = 0;
						int k;
						for (k=j;k<realMathStrings[i].length() && realMathStrings[i].charAt(k) != ')' && (pCount != 0 || k==j);k++)
						{
							if (realMathStrings[i].charAt(k) == '(')
							{
								pCount++;
							}
							if (realMathStrings[i].charAt(k) == ')')
							{
								pCount--;
							}
							newString = newString.concat(String.valueOf(realMathStrings[i].charAt(k)));
						}
						newString = newString.concat(")");
						mathParens[i][parenIndex] = newString;
						for (int m=j;m<=k;m++)
						{
							usedIndexes[uIndex] = m;
							uIndex++;
						}
						parenIndex++;
						continue;
					}
					else if (isNotUsed(j, usedIndexes))
					{
						int k;
						for (k=j;k<realMathStrings[i].length() && realMathStrings[i].charAt(k) != '(' && isNotUsed(k, usedIndexes);k++)
						{
							newString = newString.concat(String.valueOf(realMathStrings[i].charAt(k)));
						}
						mathParens[i][parenIndex] = newString;
						for (int m=j;m<k;m++)
						{
							usedIndexes[uIndex] = m;
							uIndex++;
						}
						parenIndex++;
						continue;
						 
					}
				}
			}
		}
		*/
		
	}
	
	private static void simplifyMATHsB()
	{
		for (int i=0; i<mathPieces.length;i++)
		{
			for (int j=0; j<mathPieces[i].length; j++)
			{
				mathPieces[i][j] = "";
			}
		}		
		
		
		for (int i=0; i<realMathStrings.length;i++)
		{
			if (realMathStrings[i] != null && realMathStrings[i] != "")
			{
				int pieceIndex = 0;
				int[] myUsedIndexes = new int [100];
				int uInd = 0;
				for (int j=0; j<realMathStrings[i].length();j++)
				{
					if (realMathStrings[i].charAt(j) == '@'  && (isNotUsed(j, myUsedIndexes) || j==0))
					{
						if (realMathStrings[i].charAt(j+3) == ':')
						{
							String theString = "";
							int k;
							for (k=j; k<realMathStrings[i].length() && !Double.isNaN(realMathStrings[i].charAt(k)) && !Character.isSpaceChar(realMathStrings[i].charAt(k)); k++)
							{
								theString = theString.concat(String.valueOf(realMathStrings[i].charAt(k)));
							}
							for (int u=j; u<=k; u++)
							{
								myUsedIndexes[uInd] = u;
								uInd++;
							}
							mathPieces[i][pieceIndex] = convertToSimpleVar(theString);
							mathPieces[i][pieceIndex] = cutSpaces(mathPieces[i][pieceIndex]);
							pieceIndex++;	
							continue;
						}
						else if (Character.isDigit(realMathStrings[i].charAt(j+3))  && (isNotUsed(j, myUsedIndexes) || j==0))
						{
							String theString = "";
							int k;
							for (k=j; k<realMathStrings[i].length() && !Double.isNaN(realMathStrings[i].charAt(k)) && !Character.isSpaceChar(realMathStrings[i].charAt(k)); k++)
							{
								theString = theString.concat(String.valueOf(realMathStrings[i].charAt(k)));
							}
							for (int u=j; u<=k; u++)
							{
								myUsedIndexes[uInd] = u;
								uInd++;
							}
							
							mathPieces[i][pieceIndex] = convertToComplexVar(theString);
							mathPieces[i][pieceIndex] = cutSpaces(mathPieces[i][pieceIndex]);
							pieceIndex++;
							continue;
						}
					}
					else if ((realMathStrings[i].charAt(j) == '(' || realMathStrings[i].charAt(j) == ')') && isNotUsed(j, myUsedIndexes) || j==0)
					{
						String theString = "";
					    theString = theString.concat(String.valueOf(realMathStrings[i].charAt(j)));
						myUsedIndexes[uInd] = j;
						uInd++;
						mathPieces[i][pieceIndex] = theString;
						mathPieces[i][pieceIndex] = cutSpaces(mathPieces[i][pieceIndex]);
						pieceIndex++;
						continue;
					}
					else if ((realMathStrings[i].charAt(j) == '+' || realMathStrings[i].charAt(j) == '-' || realMathStrings[i].charAt(j) == '*') && isNotUsed(j, myUsedIndexes) || j==0)
					{
						String theString = "";
					    theString = theString.concat(String.valueOf(realMathStrings[i].charAt(j)));
						myUsedIndexes[uInd] = j;
						uInd++;
						mathPieces[i][pieceIndex] = theString;
						mathPieces[i][pieceIndex] = cutSpaces(mathPieces[i][pieceIndex]);
						pieceIndex++;
						continue;
					}
					else if (realMathStrings[i].charAt(j) == '/' && isNotUsed(j, myUsedIndexes) || j==0)
					{
						String theString = "";
					    theString = " div ";
						myUsedIndexes[uInd] = j;
						uInd++;
						mathPieces[i][pieceIndex] = theString;
						mathPieces[i][pieceIndex] = cutSpaces(mathPieces[i][pieceIndex]);
						pieceIndex++;
						continue;
					}
					else if (!Character.isSpaceChar(realMathStrings[i].charAt(j)) && isNotUsed(j, myUsedIndexes) || j==0)
					{
						String theString = "";
						int k;
						for (k=j; k<realMathStrings[i].length() && realMathStrings[i].charAt(k) != '+' && realMathStrings[i].charAt(k) != '-' && realMathStrings[i].charAt(k) != '*' && realMathStrings[i].charAt(k) != '/' && realMathStrings[i].charAt(k) != '(' && realMathStrings[i].charAt(k) != ')'; k++)
						{
							theString = theString.concat(String.valueOf(realMathStrings[i].charAt(k)));
						}
						for (int u=j; u<k; u++)
						{
							myUsedIndexes[uInd] = u;
							uInd++;
						}
						mathPieces[i][pieceIndex] = theString;
						mathPieces[i][pieceIndex] = cutSpaces(mathPieces[i][pieceIndex]);
						pieceIndex++;
						continue;
					}
				}
				
			}
		}
		
		
	}
	
	private static void convertAll()
	{
		
		convertAts();
		convertSpaces();
		convertBrackets();
		convertFMTs();
		convertPADs();
		convertLOOPs();
		convertMATHs();
		
	}
	
	private static void convertMATHs()
	{
		convertMathVarsAndPieces();
		combineMathPieces();
		combineMathVars();
		convertMathStrings();
		
		for (int i=0; i<mathStrings.length; i++)
		{
			if (mathStrings[i] != null && mathStrings[i] != "")
			{
				modifiedMATHs[i] = mathVarsB[i];
				modifiedMATHs[i] = modifiedMATHs[i].concat(modifiedMathStrings[i]);
			}
		}
		
	}
	
	private static void convertMathStrings()
	{
		for (int i=0; i<modifiedMathPiecesB.length;i++)
		{
			if (modifiedMathPiecesB[i] != null && modifiedMathPiecesB[i] != "")
			{
				modifiedMathStrings[i] = startXML;
				modifiedMathStrings[i] = modifiedMathStrings[i].concat(modifiedMathPiecesB[i]);
				modifiedMathStrings[i] = modifiedMathStrings[i].concat(endXML);
			}
		}
	}
	
	private static void combineMathVars()
	{
		for (int i=0; i<mathVars.length; i++)
		{
			mathVarsB[i] = "";
			for (int j=0; j<mathVars[i].length; j++)
			{
				if (mathVars[i][j] != null && mathVars[i][j] != "")
				{
					mathVarsB[i] = mathVarsB[i].concat(mathVars[i][j]);
				}
			}
		}
	}
	
	private static void combineMathPieces()
	{
		for (int i=0; i<modifiedMathPieces.length;i++)
		{
			modifiedMathPiecesB[i] = "";
			for (int j=0; j<modifiedMathPieces[i].length; j++)
			{
				if (modifiedMathPieces[i][j] != null && modifiedMathPieces[i][j] != "")
				{
					modifiedMathPiecesB[i] = modifiedMathPiecesB[i].concat(modifiedMathPieces[i][j]);
				}
			}
		}
	}
	
	private static void convertMathVarsAndPieces()
	{
		int mathVarCount = 0;
		for (int i=0; i<mathPieces.length;i++)
		{
			int mathVarIndex = 0;
			for (int j=0; j<mathPieces[i].length;j++)
			{
				if (mathPieces[i][j] != null && mathPieces[i][j] != "")
				{				
					//@s
					if (mathPieces[i][j].charAt(0) == '<' && mathPieces[i][j].charAt(1) == 'x')
					{
						mathVars[i][mathVarIndex] = "<xsl:variable name=\"math" + mathVarCount + "\">" + mathPieces[i][j] + "</xsl:variable>";
						modifiedMathPieces[i][j] = "$math" + mathVarCount + " ";
						mathVarIndex++;
						mathVarCount++;
					}
					// ()
					else if (mathPieces[i][j].charAt(0) == '(' || mathPieces[i][j].charAt(0) == ')')
					{
						modifiedMathPieces[i][j] = mathPieces[i][j];
					}
					//+-*
					else if (mathPieces[i][j].charAt(0) == '+' || mathPieces[i][j].charAt(0) == '-' || mathPieces[i][j].charAt(0) == '*')
					{
						modifiedMathPieces[i][j] = mathPieces[i][j];
					}
					else if (mathPieces[i][j].length() >= 3) //   /
					{
						if ((mathPieces[i][j].charAt(0) == 'd' && mathPieces[i][j].charAt(1) == 'i' && mathPieces[i][j].charAt(2) == 'v'))
						{
							modifiedMathPieces[i][j] = mathPieces[i][j];
						}
						else // other >=3 nums
						{
							mathVars[i][mathVarIndex] = "<xsl:variable name=\"math" + mathVarCount + "\">" + mathPieces[i][j] + "</xsl:variable>";
							modifiedMathPieces[i][j] = "$math" + mathVarCount + " ";
							mathVarIndex++;
							mathVarCount++;
						}
					}
					//numbers
					else
					{
						mathVars[i][mathVarIndex] = "<xsl:variable name=\"math" + mathVarCount + "\">" + mathPieces[i][j] + "</xsl:variable>";
						modifiedMathPieces[i][j] = "$math" + mathVarCount + " ";
						mathVarIndex++;
						mathVarCount++;
					}
				}
			}
		}	
	}
	
	private static void convertLOOPs()
	{
		for (int i=0; i<loopStrings.length; i++)
		{
			if (loopStrings[i] != null && loopStrings[i] != "")
			{
				modifiedLOOPs[i] = loopStart;
				modifiedLOOPs[i] = modifiedLOOPs[i].concat(loopID[i]).concat("\">");
				modifiedLOOPs[i] = modifiedLOOPs[i].concat(convertLoopCond(i));
				modifiedLOOPs[i] = modifiedLOOPs[i].concat(convertLoopOutput(i));
				modifiedLOOPs[i] = modifiedLOOPs[i].concat(stringEndIf);
				modifiedLOOPs[i] = modifiedLOOPs[i].concat(loopEnd);
			}
		}
	}
	
	private static String convertLoopOutput(int index)
	{
		String returnString = "";
		String string = cutDollarSign(loopOutputs[index]);
		returnString = returnString.concat(convertCondDEF(string, true));
		return returnString;
	}
	
 	private static String convertLoopCond(int index)
	{
		String returnString = "";
		String string = loopCondition[index];
		
		int[] andOrFirstIndex = new int[100];
		String[] andOr = new String[100];
		int aoInd = 0;
		
		String[] cond = new String[100];
		int[] condIndexes = new int[100];
		int condInd = 0;
		int condCount = 0;
		int numOfConditions = 0;
		//set condition indexes
		for (int j=0; j<string.length(); j++)
		{
			if (string.charAt(j) == '<' || string.charAt(j) == '>' || string.charAt(j) == '=')
			{
				condIndexes[condInd] = j;
				condInd++;
				numOfConditions++;
				if (string.charAt(j+1) == '=' || string.charAt(j+1) == '>')
				{
					j = j+1;
				}
			}
			else if (string.charAt(j) == 'A' && (j+2 < string.length()))
				{
					if (string.charAt(j+1) == 'N' && string.charAt(j+2) == 'D')
					{
						andOrFirstIndex[aoInd] = j;
						andOr[aoInd] = "and ";
						aoInd++;
					}
				}
			else if (string.charAt(j) == 'O' && (j+1 < string.length()))
				{
					if (string.charAt(j+1) == 'R')
					{
						andOr[aoInd] = "or ";
						andOrFirstIndex[aoInd] = j;
						aoInd++;
					}
				}
			
			
		}
		//init cond array
		for (int j=0; j<cond.length; j++)
		{
			cond[j] = "";
		}
		//convert conditions
		for (int theInd : condIndexes)
		{
			if (string.charAt(theInd) == '<')
			{
				if (string.charAt(theInd+1) == '=')
				{
					cond[condCount] = " &lt;=";
				}
				else if (string.charAt(theInd+1) == '>')
				{
					cond[condCount] = " !=";
				}
				else
				{
					cond[condCount] = " &lt;";
				}
			}
			else if (string.charAt(theInd) == '>')
			{
				if (string.charAt(theInd+1) == '=')
				{
					cond[condCount] = " &gt;=";
				}
				else
				{
					cond[condCount] = " &gt;";	
				}
			}
			else if (string.charAt(theInd) == '=')
			{
				cond[condCount] = " =";
			}
			condCount++;
		}
		
		String[] compare = new String[100];
		for (int j=0; j<compare.length; j++)
		{
			compare[j] = "";
		}
		int compInd = 0;
		for (int k=0; k<condIndexes.length; k++)
			if (condIndexes[k] != 0 || k==0 )
			{
				for (int j=condIndexes[k]; j<string.length() && (j<andOrFirstIndex[k] || andOrFirstIndex[k] == 0); j++)
				{
					if (string.charAt(j) == '`')
					{
						compare[compInd] = compare[compInd].concat("'");
					}
					else
					{
						compare[compInd] = compare[compInd].concat(String.valueOf(string.charAt(j)));
					}
				}
				compInd++;
			}
		
		for (int i=0; i<compare.length; i++)
		{
			if (compare[i] != null && compare[i] != "")
			{
				compare[i] = cutCondOutOfComp(compare[i]);
			}
		}
		/*
		String[] numberAfterColon = new String[100];
		int nACInd = 0;
		for (int j=0; j<numberAfterColon.length; j++)
		{
			numberAfterColon[j] = "";
		}
		for (int j=0; j<string.length(); j++)
		{
			if (string.charAt(j) == ':')
			{
				for (int k=j+1; k<string.length() && Character.isDigit(string.charAt(k)); k++)
				{
					numberAfterColon[nACInd] = numberAfterColon[nACInd].concat(String.valueOf(string.charAt(k)));
				}
				nACInd++;
			}
		}
		*/
		String var = "";
		String[] loopCond = setLoopConds(string, numOfConditions);
		for (int j=0; j<numOfConditions; j++)
		{
			var = var.concat("<xsl:variable name=\"loop" + loopVarCount + "\">");
			//var = var.concat(startXML).concat(loopID[index] + "n_" + numberAfterColon[j]).concat(endXML);
			var = var.concat(convertCondDEF(loopCond[j], false));
			var = var.concat("</xsl:variable>");
			loopVarCount++;
		}	
		returnString = returnString.concat(var);
		
		returnString = returnString.concat(stringStartIf);
		for (int k=0; k<numOfConditions; k++)
		{
			returnString = returnString.concat("$loop" + loopCount).concat(cond[k]).concat(compare[k]);//.concat(andOR[k]);
			if (andOr[k] != null && andOr[k] != "")
			{
				returnString = returnString.concat(andOr[k]);
			}
			loopCount++;
		}
		returnString = returnString.concat("\">");
		/*
		for (int j=0; j<numOfConditions; j++)
		{
		loopNumAfterColon[index][j] = numberAfterColon[j];
		}
		*/
		return returnString;
	}
 	
 	private static String[] setLoopConds(String theString, int numOfConds)
 	{
 		String[] returnArray = new String[250];
 		int retInd = 0;
 		for (int i=0; i<numOfConds; i++)
 		{
 			returnArray[retInd] = "";
 			for (int j=0; j<theString.length() && theString.charAt(j) != '<' && theString.charAt(j) != '>' && theString.charAt(j) != '='; j++)
 			{
 				returnArray[retInd] = returnArray[retInd].concat(String.valueOf(theString.charAt(j)));
 			}
 			returnArray[retInd] = cutDollarSign(returnArray[retInd]);
 			returnArray[retInd] = cutEndSpaces(returnArray[retInd]);
 			retInd++;
 		}
 		return returnArray;
 	}
 	
 	private static String cutEndSpaces(String string)
 	{
 		String retStr = "";
 		boolean isSpace = true;
 		int i;
 		for (i=string.length() - 1; i>=0 && isSpace; i--)
 		{
 			if (!Character.isSpaceChar(string.charAt(i)))
 			{
 				isSpace = false;
 			}
 		}
 		for (int j=0; j<string.length() && (j<i+2 || i==0); j++)
 		{
 			retStr = retStr.concat(String.valueOf(string.charAt(j)));
 		}
 		return retStr;
 	}
 	
 	private static String cutDollarSign(String string)
 	{
 		String retStr = "";
 		for (int i=0; i<string.length(); i++)
 		{
 			if (string.charAt(i) == '$')
 			{
 			}
 			else
 			{
 				retStr = retStr.concat(String.valueOf(string.charAt(i)));
 			}
 		}
 		return retStr;
 	}
 	
 	private static String cutCondOutOfComp(String string)
 	{
 		String retStr = "";
 		for (int i=0; i<string.length(); i++)
 		{
 			if (string.charAt(i) == '<' || string.charAt(i) == '>' || string.charAt(i) == '=')
 			{
 			}
 			else
 			{
 				retStr = retStr.concat(String.valueOf(string.charAt(i)));
 			}
 		} 		
 		return retStr;
 	}
	
	private static void convertPADs()
	{
		for (int i=0; i<padStrings.length; i++)
		{
			if (padStrings[i] != null && padStrings[i] != "")
			{
				if (padStrings[i].charAt(4) == 'L')
				{
					modifiedPads[i] = convertPadLeft(i);
				}
				else
				{
					modifiedPads[i] = convertPadRight(i);
				}
			}
		}
	}
	
	private static String convertPadLeft(int index)
	{
		//String var = "";
		//int varInd = 0;
		/*
		if (hasAts(padAuxiliary[index]))
		{
			var = var.concat("<xsl:variable name=\"pad");
			var = var.concat(String.valueOf(varIndex)).concat("\">");
			var = var.concat(convertCondDEF(padAuxiliary[index]));
			var = var.concat("</xsl:variable>");
			varIndex++;
		}
		System.out.println("VAR " + var);
		*/
		String convString = "";//var;
		convString = convString.concat(startXML);
		String sID = padID[index];
		double iID = Double.valueOf(sID);
		String sNumSpaces = padNumOfSpaces[index];
		
		int numSpaces = Integer.valueOf(sNumSpaces);
		char id = (char) iID;
		String aux = padAuxiliary[index];
		
		int leftOver = numSpaces - aux.length();
		for (int i=0; i<leftOver;i++)
		{
			convString = convString.concat(String.valueOf(id));
		}
		/*
		for (int i=0; i<varInd;i++)
		{
		convString = convString.concat("$pad" + i);
		}
		*/
		convString = convString.concat(aux);
		convString = convString.concat(endXML);
		return convString;
	}
	
	private static String convertPadRight(int index)
	{
		//String var = "";
		//int varInd = 0;
		/*
		if (hasAts(padAuxiliary[index]))
		{
			var = var.concat("<xsl:variable name=\"pad");
			var = var.concat(String.valueOf(varIndex)).concat("\">");
			var = var.concat(convertCondDEF(padAuxiliary[index]));
			var = var.concat("</xsl:variable>");
			varIndex++;
		}
		System.out.println("VAR " + var);
		*/
		String convString = "";//var;
		convString = convString.concat(startXML);
		String sID = padID[index];
		double iID = Double.valueOf(sID);
		String sNumSpaces = padNumOfSpaces[index];
		
		int numSpaces = Integer.valueOf(sNumSpaces);
		char id = (char) iID;
		String aux = padAuxiliary[index];
		
		int leftOver = numSpaces - aux.length();
		for (int i=0; i<leftOver;i++)
		{
			convString = convString.concat(String.valueOf(id));
		}
		
		convString = convString.concat(aux);
		/*
		for (int i=0; i<varInd;i++)
		{
		convString = convString.concat("$pad" + i);
		}
		*/
		convString = convString.concat(endXML);
		return convString;
	}
	
	/*
	private static boolean hasAts(String string)
	{
		boolean hasAts = false;
		for (int i=0; i<string.length(); i++)
		{
			if (string.charAt(i) == '@')
			{
				hasAts = true;
			}
		}
		return hasAts;
	}
	*/
	
	private static void convertFMTs()
	{
		convertFMTFormats();
		convertFMTAuxs();
		
		/*
		for (int i=0;i<fmtStrings.length;i++)
		{
			if (fmtStrings[i] != null && fmtStrings[i] != "")
			{
				modifiedFMTs[i] = modifiedFMTAuxs[i];
				modifiedFMTs[i] = modifiedFMTs[i].concat(modifiedFMTFormats[i]);
			}
		}
		*/
	}
	
	private static void convertFMTAuxs()
	{
		for (int i=0; i<fmtStrings.length;i++)
		{
			if (fmtStrings[i] != null && fmtStrings[i] != "")
			{
				modifiedFMTAuxs[i] = convertAux(fmtAuxiliary[i], i);
			}
		}
		
	}
	
	private static void convertFMTFormats()
	{
		for (int i=0; i<fmtStrings.length;i++)
		{
			if (fmtStrings[i] != null && fmtStrings[i] != "")
			{
				modifiedFMTFormats[i] = convertFMT(fmtFormat[i]);
			}
		}
	}
	
	private static String convertFMT(String string)
	{
		String convString = "";
				
		
		return convString;
	}
	
	private static String convertAux(String auxString, int index)
	{
		String convString = "";
		String var = getVarForAux(auxString, index);
		convString = convString.concat(var).concat(fmtStart).concat(fmtType[index]);
		convString = convString.concat("($fmt").concat(String.valueOf(index));
		convString = convString.concat(", ");
		return convString;
	}
	
	private static String getVarForAux(String string, int ind)
	{
		String varString = "";
		varString = varString.concat("<xsl:variable name=\"fmt" + ind + "\">");
		varString = varString.concat(convertCondDEF(string, false));
		varString = varString.concat("</xsl:variable>");
		return varString;
	}
	
	private static void convertBrackets()
	{
		convertParenBrackets();
		convertCurlyBrackets();
		
		for (int i=0;i<bracketStrings.length;i++)
		{
			if (bracketStrings[i] != null && bracketStrings[i] != "")
			{
				modifiedBrackets[i] = modifiedParenBrackets[i];
				modifiedBrackets[i] = modifiedBrackets[i].concat(modifiedCurlyBrackets[i]);
				modifiedBrackets[i] = modifiedBrackets[i].concat(stringEndIf);
			}
		}
				
	}
	
	private static void convertParenBrackets()
	{
		for (int i=0;i<parenBracketStrings.length;i++)
		{
			if (parenBracketStrings[i] != null && parenBracketStrings[i] != "")
			{
				modifiedParenBrackets[i] = convertParenBracket(parenBracketStrings[i]);//does not include endif. endif is appended to last {} statement.
			}
		}
	}
	
	private static void convertCurlyBrackets()
	{
		for (int i=0;i<curlyBracketStrings.length;i++)
		{
			if (curlyBracketStrings[i] != null)
			{
				for (int j=0;j<curlyBracketStrings[i].length;j++)
				{
					if (curlyBracketStrings[i][j] != null)
					{
						partlyModifiedCurlyBrackets[i][j] = convertCondDEF(curlyBracketStrings[i][j], false); //same code as () statement
					}
				}
			}
		}
		for (int i=0;i<partlyModifiedCurlyBrackets.length;i++)
		{
			if (partlyModifiedCurlyBrackets[i] != null)
			{
				modifiedCurlyBrackets[i] = "";
				for (int j=0;j<partlyModifiedCurlyBrackets[i].length;j++)
				{
					if (partlyModifiedCurlyBrackets[i][j] != null)
					{
						modifiedCurlyBrackets[i] = modifiedCurlyBrackets[i].concat(partlyModifiedCurlyBrackets[i][j]);
					}
				}
			}
		}
		
	}
	
	private static String convertParenBracket(String DEFString)
	{ //need expression
		String var = makeVarsForCond(DEFString);
		getComparisons(DEFString);
		String convString = var; //<xsl:if test="
		convString = convString.concat(stringStartIf);
		int varInd = 0;
		for (String compare : compareStrings)
		{
			if (compare != null && compare != "")
			{
				//set ` to '
				compare = compare.replace('`', '\'');
				convString = convString.concat("$cond" + (varInd)).concat(compare);
				varInd++;
			}
		}		
		convString = convString.concat("\">");
		return convString;
	}
	
	private static void convertSpaces()
	{
		int index = 0;
		for (String spaceString : spaceTextStrings)
		{
			if (spaceString != null && spaceString != "")
			{
				modifiedSpaceAndText[index] = convertSpaceText(spaceString);
				index++;
			}
		}
	}
	
	private static void getComparisons(String theString)
	{
		String[] retStrings = new String[50];
		int equalCount = 0;
		int[] equalIndexes = new int[50];
		int equalIndex = 0;
		for (int i=0;i<theString.length();i++)
		{
			if (theString.charAt(i) == '=' || theString.charAt(i) == '<' || theString.charAt(i) == '>')
			{
				if (theString.charAt(i+1) == '=' || theString.charAt(i+1) == '>')
				{
					equalIndexes[equalIndex] = i;
					equalIndex++;
					equalCount++;
					i = i+2;
				}
				else
				{
					equalIndexes[equalIndex] = i;
					equalIndex++;
					equalCount++;
				}
				
			}
		}
		for (int i=0; i<equalCount;i++)
		{
			retStrings[i] = "";
		}
		for (int i=0; i<equalCount;i++)
		{
			for (int j=equalIndexes[i]; j<theString.length() && (j==equalIndexes[i] +1 || theString.charAt(j) != '`');j++)
			{
				if (j != theString.length() - 1)
				{
					if (theString.charAt(j) == '<')
					{
						if (theString.charAt(j+1) == '>')
						{
							retStrings[i] = retStrings[i].concat(" != ");
						}
						else if(theString.charAt(j+1) == '=')
						{
							retStrings[i] = retStrings[i].concat(" &lt;= ");
						}
						else
						{
							retStrings[i] = retStrings[i].concat(" &lt; ");
						}
					}
					else if (theString.charAt(j) == '>')
					{
						if (theString.charAt(j+1) == '=')
						{
							retStrings[i] = retStrings[i].concat(" &gt;= ");
						}
						else
						{
							retStrings[i] = retStrings[i].concat(" &gt; ");
						}
					}
					else
					{
						retStrings[i] = retStrings[i].concat(" = ");
					}
				}
			}
			retStrings[i] = retStrings[i].concat("`");
			if (i != equalCount-1)
			{
				if (orIndexes[i+1][1] != 99999)
				{
					retStrings[i] = retStrings[i].concat(" or ");
				}
				else if (andIndexes[i+1][1] != 99999)
				{
					retStrings[i] = retStrings[i].concat(" and ");
				}
				else
				{
					retStrings[i] = retStrings[i].concat(" ERROR ");
				}
			}
		}
		
		compareStrings = retStrings;
	}
	
	private static String makeVarsForCond(String theString)
	{
		int equalIndexes[] = new int[50]; //also includes < and >
		int equalIndex = 0;
		int numOfEquals = 0;
		
		for (int i=0;i<theString.length();i++)
		{
			if (theString.charAt(i) == '=' || theString.charAt(i) == '>' || theString.charAt(i) == '<')
			{
				numOfEquals++;
				equalIndexes[equalIndex] = i;
				equalIndex++;
			}
		}
		String varString = "";
		setORANDindexes(theString);
		
		for (int j=0;j<numOfEquals;j++)
		{
			varString = varString.concat("<xsl:variable name=\"cond" + varIndex + "\">");
			varIndex++;
			String condDEF = "";
			int k=orIndexes[j][1] + 1;
			k = orIndexes[j][1] + 1;
			for (int i=k;i<theString.length() && i<equalIndexes[j];i++)
			{
				condDEF = condDEF.concat(String.valueOf(theString.charAt(i)));
			}
			condDEF = cutSpaces(condDEF);
			varString = varString.concat(convertCondDEF(condDEF, false));
			varString = varString.concat("</xsl:variable>");
		}
			return varString;
	}
	
	private static String cutSpaces(String cond)
	{
		String string = "";
		int i;
		for (i=0; i<cond.length() && Character.isSpaceChar(cond.charAt(i));i++) {}
		for (int j=i; j<cond.length();j++)
		{
			string = string.concat(String.valueOf(cond.charAt(j)));
		}
		
		return string;
	}
	
	private static void setORANDindexes(String aString)
	{
		int index = 1;
		for (int i=0; i<aString.length();i++)
		{
			if (aString.charAt(i) == 'O')
			{
				if (aString.charAt(i+1) == 'R')
				{
				orIndexes[index][0] = i;
				orIndexes[index][1] = i+1;
				andIndexes[index][1] = 99999;
				index++;
				}
			}
			if (aString.charAt(i) == 'A')
			{
				if (aString.charAt(i+1) == 'N')
				{
					if (aString.charAt(i+2) == 'D')
					{
						andIndexes[index][0] = i;
						andIndexes[index][1] = i+2;
						orIndexes[index][1] = 99999;
						index++;
					}
				}
			}
		}
	}
		
	private static String convertCondDEF(String theString, boolean isLoop)
	{
		
		String[] arrayDEF = new String[50];
		String[] arrayXML = new String[50];
		int myIndCount = 0;
		int myUsedInd[] = new int[50];
		int myUsedIndCount = 0;
		
		String modString = "";
		
		for (int i=0;i<theString.length();i++)
		{			
			modString = "";
			//ATS (@s)
			if (theString.charAt(i) == '@')
			{
				int j;
					for (j = i;j<theString.length() && !Double.isNaN(theString.charAt(j)) && !Character.isSpaceChar(theString.charAt(j)) && theString.charAt(j) != '}' && theString.charAt(j) != '=';j++)
					{
						modString = modString.concat(String.valueOf(theString.charAt(j)));
					}
				
				arrayDEF[myIndCount] = modString;
				myIndCount++;
				for (int k=i;k<=j;k++) //<=
				{
					myUsedInd[myUsedIndCount] = k;
					myUsedIndCount++;
				}
				
				continue;
			}
			
			else if (Character.isSpaceChar(theString.charAt(i)) || (Character.isLetterOrDigit(theString.charAt(i))) && isNotUsed(i, myUsedInd))
			{
				int j;
				for (j=i;j<theString.length() && theString.charAt(j) != '@' && theString.charAt(j) != '}';j++)
				{
					modString = modString.concat(String.valueOf(theString.charAt(j)));
				} 
				arrayDEF[myIndCount] = modString;
				myIndCount++;
				for (int k=i;k<j;k++) //<=
				{
					myUsedInd[myUsedIndCount] = k;
					myUsedIndCount++;
				}
			}
		}
		int index = 0;
		for (String aString : arrayDEF)
		{
			if (aString != null && aString != "")
			{
				if (aString.charAt(0) == '@')
				{
					if (aString.charAt(3) == ':')
					{
						if (isLoop)
						{
							arrayXML[index] = convertToLoopVar(aString);
						}
						else
						{
							arrayXML[index] = convertToSimpleVar(aString);
						}
					}
					else
					{
						arrayXML[index] = convertToComplexVar(aString);
					}
				}
				else
				{
					arrayXML[index] = convertSpaceText(aString);
				}

				index++;
			}
		}
		
		for (String string : arrayXML)
		{
			if (string != null && string != "")
			{
				modString = modString.concat(string);
			}
		}
		
		return modString;
	}
	
	private static void convertAts()
	{
		int index = 0;
		for (String atString : atStrings)
		{
			if (atString != null && atString != "")
			{
				if (atString.charAt(3) == ':')
				{
					modifiedAts[index] = convertToSimpleVar(atString);
				}
				else
				{
					modifiedAts[index] = convertToComplexVar(atString);
				}
				index++;
			}
		}
	}
	
	private static String convertSpaceText(String DEFString)
	{
		String convString = startXML;
		convString = convString.concat("'").concat(DEFString).concat("'").concat(endXML);		
		return convString;
	}
	
	private static String convertToSimpleVar(String DEFString)
	{
		String convString = startXML + "ApVariables/";
		String idLetters = String.valueOf(DEFString.charAt(1)) + String.valueOf(DEFString.charAt(2));
		convString = convString.concat(idLetters).concat("_");
		for (int i=4;i<DEFString.length();i++)
		{
			convString = convString.concat(String.valueOf(DEFString.charAt(i)));
		}
		convString = convString.concat(endXML);
		
		return convString;
	}
	
	private static String convertToComplexVar(String DEFString)
	{
		String convString = startXML + "ApVariables/";
		String idLetters = String.valueOf(DEFString.charAt(1)) + String.valueOf(DEFString.charAt(2));
		String idNums = "";
		int i;
		for (i=3;DEFString.charAt(i) != ':';i++)
		{
			idNums = idNums.concat(String.valueOf(DEFString.charAt(i)));
		}
		
		convString = convString.concat(idLetters).concat("[").concat(idNums).concat("]").concat("/").concat(idLetters).concat("n_");
		
		for (int j=i+1;j<DEFString.length();j++)
		{
			convString = convString.concat(String.valueOf(DEFString.charAt(j)));
		}
		convString = convString.concat(endXML);
		
		return convString;
	}
	
	private static String convertToLoopVar(String DEFString)
	{
		String convString = startXML + "ApVariables/";
		String idLetters = String.valueOf(DEFString.charAt(1)) + String.valueOf(DEFString.charAt(2));
		convString = convString.concat(idLetters).concat("n").concat("_");
		for (int i=4;i<DEFString.length();i++)
		{
			convString = convString.concat(String.valueOf(DEFString.charAt(i)));
		}
		convString = convString.concat(endXML);
		
		return convString;
	}
	
	private static void splitToLogicalParts()
	{
		int indexCount = 0; //universal index count
		int bracketIndex = 0; //index count for [] strings
		int atIndex = 0; //index count for remaining @ strings
		int spaceIndex = 0; //index count for leftover spaces and text
		int fmtIndex = 0; // for @FMT() strings
		int padIndex = 0;// for padl and padr
		int loopIndex = 0; //for $LOOPs
		int mathIndex = 0; // for @MATH() functions

		for (int i=0; i<stringDEF.length();i++)
		{
			//BRACKETS
			String newString = "";
			if (stringDEF.charAt(i) == '[')
			{
				if (stringDEF.charAt(i+1) == '$')
				{
					if (stringDEF.charAt(i+2) == 'L')
					{
						int j;
						for (j = i;stringDEF.charAt(j) != ']';j++)
						{
							newString = newString.concat(String.valueOf(stringDEF.charAt(j)));
						}
						newString = newString.concat("]");
						loopStrings[loopIndex] = newString;
						allStringsDEF[indexCount] = newString;
						for (int k=i;k<=j;k++)
						{
							usedIndexes[usedIndexCount] = k;
							usedIndexCount++;
						}
						indexCount++;
						loopIndex++;

						continue;
					}
				}
				else
				{
					System.out.println("BRACKET");
					int j;
					for (j = i;stringDEF.charAt(j) != ']';j++)
					{
						newString = newString.concat(String.valueOf(stringDEF.charAt(j)));
					}
					newString = newString.concat("]");
					bracketStrings[bracketIndex] = newString;
					allStringsDEF[indexCount] = newString;
					bracketIndexes[bracketIndex][0] = i;
					bracketIndexes[bracketIndex][1] = j;
					for (int k=i;k<=j;k++)
					{
						usedIndexes[usedIndexCount] = k;
						usedIndexCount++;
					}
					indexCount++;
					bracketIndex++;

					continue;
				}
				
			}
			//ATS (@s)
			else if (stringDEF.charAt(i) == '@' && isNotUsedIndex(i))
			{				
				if (stringDEF.charAt(i+3) == 'T')
				{
					if (stringDEF.charAt(i+1) == 'M')
					{
						System.out.println("MATH");
						int j;
						int parenCount = 0;
						for (j = i;j<stringDEF.length() && (parenCount != 0 || j<=i+5);j++)
						{
							if (stringDEF.charAt(j) == '(')
							{
								parenCount++;
							}
							if (stringDEF.charAt(j) == ')')
							{
								parenCount--;
							}
							newString = newString.concat(String.valueOf(stringDEF.charAt(j)));
						}
						mathStrings[mathIndex] = newString;
						allStringsDEF[indexCount] = newString;
						for (int k=i;k<j;k++) //<=
						{
							usedIndexes[usedIndexCount] = k;
							usedIndexCount++;
						}
						indexCount++;
						mathIndex++;
					
						continue;
					}
					else
					{
						System.out.println("FMT");
						int j;
						int parenCount = 0;
						for (j = i;j<stringDEF.length() && (parenCount != 0 || j<=i+4);j++)
						{
							if (stringDEF.charAt(j) == '(')
							{
								parenCount++;
							}
							if (stringDEF.charAt(j) == ')')
							{
								parenCount--;
							}
							newString = newString.concat(String.valueOf(stringDEF.charAt(j)));
						}
						fmtStrings[fmtIndex] = newString;
						allStringsDEF[indexCount] = newString;
						for (int k=i;k<j;k++) //<=
						{
							usedIndexes[usedIndexCount] = k;
							usedIndexCount++;
						}
						indexCount++;
						fmtIndex++;
					
						continue;
					}
				}
				else if (stringDEF.charAt(i+3) == 'D')
				{
					System.out.println("PAD");
					int j;
					int parenCount = 0;
					for (j = i;j<stringDEF.length() && (parenCount != 0 || j<=i+5);j++)
					{
						if (stringDEF.charAt(j) == '(')
						{
							parenCount++;
						}
						if (stringDEF.charAt(j) == ')')
						{
							parenCount--;
						}
						newString = newString.concat(String.valueOf(stringDEF.charAt(j)));
					}
					padStrings[padIndex] = newString;
					allStringsDEF[indexCount] = newString;
					for (int k=i;k<j;k++) //<=
					{
						usedIndexes[usedIndexCount] = k;
						usedIndexCount++;
					}
					indexCount++;
					padIndex++;
					
					continue;
				}
				else
				{
					System.out.println("AT");
					int m;
					for (m=i; m<stringDEF.length() && stringDEF.charAt(m) != ':'; m++){}
					int j;
					for (j = i;j<stringDEF.length() && !Double.isNaN(stringDEF.charAt(j)) && stringDEF.charAt(j) != '[' && !Character.isSpaceChar(stringDEF.charAt(j)) && (Character.isDigit(stringDEF.charAt(j)) || j <= m);j++)
					{
						newString = newString.concat(String.valueOf(stringDEF.charAt(j)));
					}
					atStrings[atIndex] = newString;
					allStringsDEF[indexCount] = newString;
					for (int k=i;k<j;k++) //<=
					{
						usedIndexes[usedIndexCount] = k;
						usedIndexCount++;
					}
					indexCount++;
					atIndex++;
					
					continue;
				}
				
			
			}
			
			else if ((Character.isSpaceChar(stringDEF.charAt(i))) && isNotUsedIndex(i))
			{
				System.out.println("SPACE");
				int j;
				for (j=i;j<stringDEF.length() && stringDEF.charAt(j) != '[' && stringDEF.charAt(j) != '@';j++)
				{
					newString = newString.concat(String.valueOf(stringDEF.charAt(j)));
				} 
				spaceTextStrings[spaceIndex] = newString;
				allStringsDEF[indexCount] = newString;
				for (int k=i;k<j;k++) //<=
				{
					usedIndexes[usedIndexCount] = k;
					usedIndexCount++;
				}
				indexCount++;
				spaceIndex++;
			}
			else if (isNotUsedIndex(i))
			{
				System.out.println("TEXT");
				int j;
				for (j=i;j<stringDEF.length() && stringDEF.charAt(j) != '[' && stringDEF.charAt(j) != '@';j++)
				{
					newString = newString.concat(String.valueOf(stringDEF.charAt(j)));
				} 
				spaceTextStrings[spaceIndex] = newString;
				allStringsDEF[indexCount] = newString;
				for (int k=i;k<j;k++) //<=
				{
					usedIndexes[usedIndexCount] = k;
					usedIndexCount++;
				}
				indexCount++;
				spaceIndex++;
			}
		}		
		
	}
	
	private static boolean isNotUsedIndex(int index)
	{
			boolean isUsed = false;
			for (int used : usedIndexes)
			{
				if (used == index)
				{
					isUsed = true;
				}
			}
			return !isUsed;
	}
	
	private static boolean isNotUsed(int index, int[] theUsedIndexes)
	{
			boolean isUsed = false;
			for (int used : theUsedIndexes)
			{
				if (used == index)
				{
					isUsed = true;
				}
			}
			return !isUsed;
	}
	
	
}